<!--
	This file is part of ELCube.
	ELCube is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	ELCube is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	You should have received a copy of the GNU Affero General Public License
	along with ELCube.  If not, see <https://www.gnu.org/licenses/>.
-->
<template>
    <nk-card v-if="data.active">
        <a-button @click="nk$calc" slot="extra" size="small" v-if="editMode">测试运行</a-button>
        <vxe-table
                ref="xTable"
                auto-resize
                resizable
                show-footer
                size="mini"
                border=inner
                :data="data.items"
                :merge-footer-items="mergeFooterItems"
                :footer-method="footerMethod"
            >
            <vxe-column field="itemIndex"          width="5%"   title="#"        ></vxe-column>
            <vxe-column field="voucherSubject"     width="30%"  title="科目"      >
                <template v-slot="{row}">{{row.voucherSubject}} {{row.voucherSubjectDesc}}</template>
                <template v-slot:footer="{row}"><span style="font-weight: 500">合计</span></template>
            </vxe-column>
            <vxe-column field="currType"           width="6%"   title="币种"      ></vxe-column>

            <vxe-column field="debitAmount"        width="12%"  title="借方金额"  align="right" formatter="nkCurrency"></vxe-column>
            <vxe-column field="creditAmount"       width="12%"  title="贷方金额"  align="right" formatter="nkCurrency"></vxe-column>
            <vxe-column field="explanation"        width="20%"  title="摘要"      >
                <template v-slot="{row}">
                    <span>{{row.explanation}}{{row.explanation&&row.assists?';':''}}</span>
                    <div v-for="item in row.assists">{{item.key}}:{{item.value}};</div>
                </template>
            </vxe-column>
            <vxe-column field="cashFlow"           width="10%"   title="现金流量"    >
                <template v-slot="{row}">{{row.cashFlow}} {{row.cashFlow&&(row.cashFlowSide===1?'(+)':'(-)')}}</template>
            </vxe-column>
            <vxe-column></vxe-column>

        </vxe-table>
    </nk-card>
</template>

<script>
    import Mixin from "Mixin";
    import NkFormat from "NkFormat";

    export default {
        mixins:[new Mixin({})],
        data(){
            return {
                mergeFooterItems:[
                    { row: 0, col: 1, rowspan: 1, colspan: 2 },
                    { row: 0, col: 5, rowspan: 1, colspan: 3 }
                ]
            }
        },
        methods:{
            footerMethod(){
                let debitAmount = 0;
                let creditAmount = 0;
                if(this.data.items){
                    this.data.items.forEach(i=>{
                        debitAmount  += i.debitAmount||0
                        creditAmount += i.creditAmount||0
                    })
                }
                return [
                    [null,'合计',null,NkFormat.nkCurrency(debitAmount),NkFormat.nkCurrency(creditAmount)]
                ]
            }
        }
    }
</script>

<style scoped>

</style>